package com.jams.goodox.utils.permission;

import android.Manifest;
import android.content.Context;

import com.jams.goodox.R;
import com.jams.goodox.listen.SuccessListener;
import com.jams.goodox.utils.TipAlertDialog;
import com.yanzhenjie.permission.AndPermission;
import com.yanzhenjie.permission.PermissionNo;
import com.yanzhenjie.permission.PermissionYes;

import java.util.List;

/**
 * Created by jams on 2017/8/16.
 * ***
 * Tel: ***
 *
 * 存储权限工具类
 * 注意点：使用该类的时候，注意不能几处同时调用，要分先后顺序，因为“SuccessListener”可能被覆盖
 */

public class WriteExternalStorageUtils {
    private Context context;
    private SuccessListener successListener;

    public WriteExternalStorageUtils(Context context){
        this.context = context;
    }

    public void checkExternalPermission(SuccessListener successListener){
        this.successListener = successListener;
        AndPermission.with(context)
                .requestCode(101)
                .callback(this)
                .permission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
                .start();
    }
    @PermissionYes(101)
    private void externalPermissionIsOk(List<String> grantedPermissions){
        if(successListener != null){
            successListener.success();
        }
    }
    @PermissionNo(101)
    private void externalPermissionIsNo(List<String> grantedPermissions){
        TipAlertDialog.showTip(context,context.getString(R.string.setting_permission),context.getString(R.string.cancel), context.getString(R.string.read_status_permission_is_need), new SuccessListener() {
            @Override
            public void success() {
                PermissionUtils.gotoMIUIPermission(context);
            }
        });
    }

}
